package com.explorx.sns.puma.im.core.controller;

import com.explorex.puma.common.dto.UserBaseInfo;
import com.explorx.sns.puma.im.api.UserInfoService;
import com.explorx.sns.puma.im.core.chat.UserInfoDomainService;
import com.explorx.sns.puma.im.core.chat.UserRelationService;
import com.explorx.sns.puma.im.core.chat.model.UserInfoModel;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@DubboService(version = "1.0.0")
@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Resource
    private UserInfoDomainService userInfoDomainService;

    @Resource
    private UserRelationService userRelationService;

    @Override
    public List<UserBaseInfo> queryBaseUserInfo(List<Long> userIds) {
        final List<UserInfoModel> usersInfo = userInfoDomainService.getUsersInfo(userIds);
        return CollectionUtils.isEmpty(usersInfo) ? Collections.EMPTY_LIST
                : usersInfo.stream().map(ele->{
                    return new UserBaseInfo(ele.getUserId(),ele.getAvatar(),ele.getUserName());
        }).collect(Collectors.toList());
    }

}
